<template>
  <div class="register-container">
    <div class="register-wrapper">
      <el-card class="register-card">
        <template #header>
          <div class="card-header">
            <h2>智慧交通系统注册</h2>
          </div>
        </template>
        <div class="card-body">
          <div class="input-group">
            <span class="input-label">账号</span>
            <el-input
              v-model="account"
              placeholder="请输入账号"
              prefix-icon="el-icon-user"
            />
          </div>
          <div class="input-group">
            <span class="input-label">密码</span>
            <el-input
              v-model="password"
              placeholder="请输入密码"
              type="password"
              show-password
              prefix-icon="el-icon-lock"
            />
          </div>
          <div class="input-group">
            <span class="input-label">确认密码</span>
            <el-input
              v-model="repassword"
              placeholder="请再次输入密码"
              type="password"
              show-password
              prefix-icon="el-icon-lock"
            />
          </div>
        </div>
        <div class="card-footer">
          <el-button
            type="primary"
            class="register-button"
            @click="handleRegister"
            >注册</el-button
          >
          <div class="login-link">
            已有账号? <router-link to="/Login">去登录</router-link>
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>
<script setup>
import { ref } from 'vue'
import { goRegister } from '../apis/user'
import { useRouter } from 'vue-router'

const account = ref('')
const password = ref('')
const repassword = ref('')
const router = useRouter()

const handleRegister = async () => {
  const req = {
    account: account.value,
    password: password.value,
    repassword: repassword.value,
  }
  console.log(req)
  const res = await goRegister(req)
  console.log(res)
  if (res.success) {
    ElMessage.success('注册成功请登录')
    router.push('/Login')
  }
}
</script>
<style scoped lang="scss">
.register-container {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  // 添加渐变背景，从紫色到蓝色的渐变
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  background-size: 200% 200%;
  animation: gradientBG 15s ease infinite;

  @keyframes gradientBG {
    0% {
      background-position: 0% 50%;
    }
    50% {
      background-position: 100% 50%;
    }
    100% {
      background-position: 0% 50%;
    }
  }

  .register-wrapper {
    width: 100%;
    max-width: 450px;
    padding: 0 20px;
  }

  .register-card {
    border-radius: 16px;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    border: none;
    backdrop-filter: blur(5px);
    background-color: rgba(255, 255, 255, 0.95);
    transition: all 0.3s ease;

    &:hover {
      transform: translateY(-5px);
      box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    }

    .el-card__header {
      padding: 25px 20px;
      background: linear-gradient(to right, #f9f9f9, #ffffff);
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.03);
      border-bottom: 1px solid #f1f1f1;
    }

    .card-header {
      display: flex;
      justify-content: center;
      align-items: center;

      h2 {
        margin: 0;
        font-size: 24px;
        color: #303133;
        font-weight: 600;
        letter-spacing: 0.5px;
      }
    }

    .card-body {
      padding: 15px 25px;

      .input-group {
        margin-bottom: 25px;

        .input-label {
          display: block;
          margin-bottom: 10px;
          color: #606266;
          font-size: 14px;
          font-weight: 500;
        }

        .el-input {
          .el-input__inner {
            border-radius: 8px;
            padding: 12px 15px;
            height: 45px;
            border-color: #dcdfe6;
          }
        }
      }
    }

    .card-footer {
      padding: 0 25px 30px;
      display: flex;
      flex-direction: column;
      align-items: center;

      .register-button {
        width: 100%;
        height: 45px;
        border-radius: 8px;
        font-size: 16px;
        font-weight: 500;
        margin-bottom: 20px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        border: none;

        &:hover {
          background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
          opacity: 0.9;
        }
      }

      .login-link {
        font-size: 14px;
        color: #606266;
        margin-top: 5px;

        a {
          color: #764ba2;
          text-decoration: none;
          font-weight: 500;
          margin-left: 5px;

          &:hover {
            color: #667eea;
            text-decoration: underline;
          }
        }
      }
    }
  }
}

// 添加响应式样式
@media (max-width: 768px) {
  .register-container {
    .register-wrapper {
      max-width: 90%;
    }

    .register-card {
      .card-header h2 {
        font-size: 20px;
      }
    }
  }
}
</style>
